﻿using System;

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.DL.Project;
using PowerCreator.LMS.DL.Project.Entity;

public partial class sysadmin_DL_Project_AddUserGroup : PowerCreator.LMS.Web.Base.WebBasePage
{
    //TOBatch objBatch = new TOBatch();
    TOUserGroup objUserGroup = new TOUserGroup();

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (IsLicensed(PowerCreator.LMS.Action.Core.ActionInfo.AddJob))
        //{
        //    Script.RedirectURL(GetRefUrl());
        //}
        if (!IsPostBack)
        {
            InitPage();
            //BinderBatch();
            int UGID = 0;
            if (Request.QueryString["UGID"] != null)
            {
                UGID = int.Parse(Request.QueryString["UGID"].ToString());
                ViewState["UGID"] = UGID.ToString();
                BinderForm(UGID);
            }
        }
    }
    protected override void InitPage()
    {
        //lbl_InfoTitle.Text = GetLanageValueByKey("lbl_AddJob_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_JobName.Text = GetLanageValueByKey("lbl_AddJob_JobName", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_JobDescription.Text = GetLanageValueByKey("lbl_AddJob_JobDescription", PowerCreator.LMS.Language.LanagetItemType.Page);

        //btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        //btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        //base.InitPage();

        //lbl_InfoTitle_AddNewType.Text = GetLanageValueByKey("lab_AddNewType_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_NewTypeName.Text = GetLanageValueByKey("lab_AddNewType_TypeName", PowerCreator.LMS.Language.LanagetItemType.Page);

        btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }


  


    private void BinderForm(int id)
    {
        VOTOUserGroup vo = new VOTOUserGroup();
        vo = objUserGroup.Load(id);

        txt_Name.Text = vo.Name;
        txt_Power.Text = vo.Powers;
        txt_Introduce.Text = vo.Description;
        

    }
    private bool CheckPageData()
    {
        string search = string.Format("Name = '{0}'", txt_Name.Text.Trim());
        if (ViewState["UGID"] != null)
        {
            search += "and UGroup_Id<>" + ViewState["UGID"].ToString();
        }
        if (objUserGroup.Count(search) != 0)
        {

            //lbl_msg_Error.Text = GetLanageValueByKey("lbl_msg_addjob_aspx_count", PowerCreator.LMS.Language.LanagetItemType.MSG);

            lbl_msg_Error.Text = "<br />" + GetLanageValueByKey("msg_AddNewType_checkMsg", PowerCreator.LMS.Language.LanagetItemType.Page);
            return false;
        }
        return true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;
        VOTOUserGroup vo = new VOTOUserGroup();
        if (ViewState["UGID"] == null)
        {
            vo.Name = txt_Name.Text.Trim();
            vo.Powers = txt_Power.Text.Trim();
            vo.Description = txt_Introduce.Text.Trim();


            if (objUserGroup.Add(vo))
            {
                string url = "ManageUserGroup.aspx";
                Script.RedirectURL(url);
            }
        }
        else
        {
            vo = objUserGroup.Load(int.Parse(ViewState["UGID"].ToString()));
            vo.Name = txt_Name.Text.Trim();
            vo.Powers = txt_Power.Text.Trim();
            vo.Description = txt_Introduce.Text.Trim();


            if (objUserGroup.Update(vo))
            {
                string url = "ManageUserGroup.aspx";
                Script.RedirectURL(url);
            }
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "ManageUserGroup.aspx";
        Script.RedirectURL(url);
    }


}
